<template>
  <div class="list-table">
    <el-form ref="queryForm" :model="queryParams" :inline="true" @submit.native.prevent>
      <el-form-item :label="$t('公司名称')" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          :placeholder="$t('公司名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <div class="area-header">
      <span class="area-header-title">{{ $t('投前 - 申报数据审核') }}</span>
    </div>
    <el-table v-loading="SBLoading" tooltip-effect="darkTable" :data="companyPortalDataSBList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('公司名称')" align="center" prop="companyName" />
      <el-table-column :label="$t('提交时间')" align="center" prop="submitTime" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('审核状态')" align="center" prop="status" width="200" />
      <el-table-column :label="$t('审核人')" align="center" prop="applyUserName" width="200" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="280">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['companyPortal:data:edit']"
            size="small"
            type="text"
            icon="el-icon-s-custom"
            @click="asyncPortalData(scope.row)"
          >{{ $t('审核通过') }}</el-button>
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['companyPortal:data:edit']"
            size="small"
            type="text"
            icon="el-icon-s-custom"
            @click="rejectPortalData(scope.row)"
          >{{ $t('驳回') }}</el-button>
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['companyPortal:data:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="viewData(scope.row, 'edit')"
          >{{ $t('检查编辑') }}</el-button>
          <el-button
            v-if="scope.row.status === '审核通过'"
            v-hasPermi="['companyPortal:data:view']"
            size="small"
            type="text"
            icon="el-icon-view"
            @click="viewData(scope.row, 'view')"
          >{{ $t('查看') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="SBTotal>0"
      :total="SBTotal"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSBList"
    />

    <div class="area-header mt-15">
      <span class="area-header-title">{{ $t('投后 - 填报数据审核') }}</span>
    </div>
    <el-table v-loading="TBLoading" :data="companyPortalDataTBList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('公司名称')" align="center" prop="companyName" />
      <el-table-column :label="$t('年份')" align="center" prop="year" width="130" />
      <el-table-column :label="$t('报告期类型')" align="center" prop="type" width="130" />
      <el-table-column :label="$t('提交时间')" align="center" prop="submitTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('审核状态')" align="center" prop="status" width="130" />
      <el-table-column :label="$t('审核人')" align="center" prop="applyUserName" width="120" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="280">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['companyPortal:data:edit']"
            size="small"
            type="text"
            icon="el-icon-s-custom"
            @click="asyncPortalData(scope.row)"
          >{{ $t('审核通过') }}</el-button>
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['companyPortal:data:edit']"
            size="small"
            type="text"
            icon="el-icon-s-custom"
            @click="rejectPortalData(scope.row)"
          >{{ $t('驳回') }}</el-button>
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['companyPortal:data:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="viewData(scope.row, 'edit')"
          >{{ $t('检查编辑') }}</el-button>
          <el-button
            v-if="scope.row.status === '审核通过'"
            v-hasPermi="['companyPortal:data:view']"
            size="small"
            type="text"
            icon="el-icon-view"
            @click="viewData(scope.row, 'view')"
          >{{ $t('查看') }}</el-button>
          <!--<el-button
            v-hasPermi="['companyPortal:data:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="TBTotal>0"
      :total="TBTotal"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getTBList"
    />
  </div>
</template>

<script>
import { listCompanyPortalSBData, listCompanyPortalTBData, delCompanyPortalData, getPortalToken, asyncPortalData, rejectPortalData } from '@/api/company/portal/companyPortalData'
export default {
  data() {
      return {
          // 申报数据遮罩层
          SBLoading: true,
          // 填报数据遮罩层
          TBLoading: true,
          // 申报数据总条数
          SBTotal: 0,
          // 填报数据总条数
          TBTotal: 0,
          // 被投企业填报-申报数据审核表格数据
          companyPortalDataSBList: [],
          // 填报数据审核表数据
          companyPortalDataTBList: [],
          // 审批状态字典
          statusOptions: [],
          // 查询参数
          queryParams: {
              companyName: undefined,
              dataType: undefined,
              year: undefined,
              type: undefined,
              submitTime: undefined,
              status: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {}
      }
  },
  created() {
      this.getSBList()
      this.getTBList()
      this.getDicts('work_flow_status').then(response => {
          this.statusOptions = response.data
      })
  },
  methods: {
    /** 查询被投企业填报-申报数据审核列表 */
    getSBList() {
        this.SBLoading = true
        listCompanyPortalSBData(this.queryParams).then(response => {
            this.companyPortalDataSBList = response.rows
            this.SBTotal = response.total
            this.SBLoading = false
        })
    },
    /** 查询被投企业填报-填报数据审核列表 */
    getTBList() {
      this.TBLoading = true
      listCompanyPortalTBData(this.queryParams).then(response => {
        this.companyPortalDataTBList = response.rows
        this.TBTotal = response.total
        this.TBLoading = false
      })
    },
    // 审批状态字典翻译
    statusFormat(row) {
      return this.selectDictLabel(this.statusOptions, row.status)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            companyId: undefined,
            companyName: undefined,
            dataType: undefined,
            reportId: undefined,
            year: undefined,
            type: undefined,
            submitTime: undefined,
            status: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined,
            remark: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getSBList()
        this.getTBList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认驳回?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delCompanyPortalData(row.id)
        }).then(() => {
          this.getSBList()
          this.getTBList()
            this.msgSuccess(this.$t('已驳回！'))
        }).catch(function() {
          this.msgError(this.$t('驳回失败!'))
        })
    },
    // 查看数据
    viewData(row, view) {
      // 获取临时token
      getPortalToken().then(res => {
          window.open(process.env.VUE_APP_BASE_COMPANY_PORTAL_URL + '/login?tempToken=' + res.data + '&companyId=' + row.companyId + '&reportId=' + row.reportId + '&dataType=' + row.dataType + '&btnView=' + view)
      })
    },
    // 入库操作
    asyncPortalData(row) {
      var _this = this
      if (row.id !== '' && row.id !== undefined) {
        this.$confirm(this.$t('审核通过之后，数据会同步到对应的标的公司内，是否确认通过?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(function() {
          _this.TBLoading = true
          return asyncPortalData(row.id).then(() => {
            _this.$notify({
              title: _this.$t('同步中...'),
              message: _this.$t('正在同步填报段信息, 这大约需要1分钟. 请在同步结束后再进行查看'),
              type: 'success',
              position: 'bottom-right',
              duration: 10000
            })
            _this.TBLoading = false
          })
        }).then(() => {
          this.getSBList()
          this.getTBList()
        }).catch(function() {
          this.msgError(this.$t('审核未通过，数据同步失败!'))
        })
      }
    },
    // 驳回数据
    rejectPortalData(row) {
      if (row.id !== '' && row.id !== undefined) {
        this.$confirm(this.$t('是否确认驳回?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(function() {
          return rejectPortalData(row.id)
        }).then(() => {
          this.getSBList()
          this.getTBList()
          this.msgSuccess(this.$t('已驳回!'))
        }).catch(function() {
          this.msgError(this.$t('驳回失败!'))
        })
      }
    }
  }
}
</script>
